#include "E_Calendar.h"
#include <iostream>
#include <string>
using namespace std;

/*These are the functions respnsible for the User Interface part of the code*/
E_Calendar ec;
Calendar c;
int choice;

void Tester_copyMeeting(){
		cout<<"What day would you like to copy a meeting from?"<<endl;
		int source_day;
		cin>>source_day;
		cout<<"What hour of that day?"<<endl;
		float source_start;
		cin>>source_start;
		cout<<"What day would you like to copy the meeting to?"<<endl;
		int dest_day;
		cin>>dest_day;
		cout<<"To what start hour of the destined day?"<<endl;
		float dest_start;
		cin>>dest_start;
		

		if(choice==1){
			E_Meeting em_source(source_start,23.999,"","");
			E_Meeting em_dest(dest_start,23.999,"","");
			ec.copyMeeting(source_day,dest_day,em_source,em_dest);
		}
		else 
		{
			Meeting m_source(source_start,23.999,"");
			Meeting m_dest(dest_start,23.999,"");
			c.copyMeeting(source_day,dest_day,m_source,m_dest);
		}
}


void Tester_delMeeting(){
		cout<<"What day would you like to delete a meeting from?"<<endl;
		int source_day;
		cin>>source_day;
		cout<<"Please enter the meeting's start hour?"<<endl;
		float del_start;
		cin>>del_start;
		cout<<"Please enter the meeting's end hour?"<<endl;
		int del_end;
		cin>>del_end;
		if(choice==1){
			E_Meeting em(del_start,del_end,"","");
			ec.deleteMeeting(source_day,em);
		}
		else 
		{
			Meeting m(del_start,del_end,"");
			c.deleteMeeting(source_day,m);
		}
}

void Tester_addMeeting() { 
		cout<<"What day would you like to add a meeting at?"<<endl;
		int day;
		cin>>day;
		cout<<"Please enter meeting start hour?"<<endl;
		float start;
		cin>>start;
		cout<<"Please enter meeting end hour?"<<endl;
		float end;
		cin>>end;
		cout<<"Please enter meeting subject?"<<endl;
		string sub;
		cin>>sub;
		if(choice==1){
			cout<<"Please write your attendees seperated by comma"<<endl;
			string attendees;
			cin>>attendees;
			E_Meeting em(start,end,sub,attendees);
			ec.addMeeting(day,em);
		}
		else 
		{
			Meeting m(start,end,sub);
			c.addMeeting(day,m);
		}
}

void Tester_printMeeting(){
	if (choice==1)
		ec.printMeetings();
	else c.printMeetings();
}

void Tester_findMeeting(){
		cout<<"What day would you like to find a meeting at?"<<endl;
		int day;
		cin>>day;
		cout<<"What hour of that day does the meeting start?"<<endl;
		float start;
		cin>> start;
		if(choice==1){
			ec.findMeeting(day,start);
		}
		else 
		{
			c.findMeeting(day,start);
		}
}
int main() { 	

string command = "";
	cout<< "Hello and welcome to your Calendar"<<endl;
	cout<< "To test the attendees enabled clendar type 1"<<endl;
	cout<< "To test the regular (no attendees) clendar type 2"<<endl;
	cin>>choice;
	if (!(choice==1||choice==2)){
		cout<<"Inavlid command";
	}
	else {
	cout<<"To add a new meeting type \"add\""<<endl;
	cout<<"To delete a meeting type \"delete\""<<endl;
	cout<<"To copy a meeting type \"copy\""<<endl;
	cout<<"To print the calendar by days type \"print\""<<endl;
	cout<<"To find(and print) type \"find\""<<endl;
	cout<<"To switch to an other calendar type \"switch\""<<endl;

	while(true) { 
	cin.clear();
	std::cin.ignore( 1024, '\n' );
	cout<< "Please enter your command: \n\n";
	cin>>command;
	
	if (command=="add") {
		Tester_addMeeting();
	}
	else if (command=="copy") {
		Tester_copyMeeting();
	}
	else if (command=="delete") {
		Tester_delMeeting();
	}
	else if (command=="print") {
		Tester_printMeeting();
	}
	else if (command=="find") {
		Tester_findMeeting();
	}
	else if (command=="switch"){
		cout<< "To test the attendees enabled clendar type 1"<<endl;
		cout<< "To test the regular (no attendees) clendar type 2"<<endl;
		cin>>choice;
		continue;
	}
	else if (command=="exit"){
		cout<<"Thank you and goodbye"<<endl;
		exit(0);
	}
	else cout<<"Command: "<<command<<" is not a valid command"<<"\n\n";

	}
	}
}





